package com.dh.example.netty.util;

import cn.hutool.json.JSONUtil;
import com.dh.example.netty.pojo.response.WsBaseResp;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * 信道util
 *
 * @author yolo
 * @date 2024/3/15 11:17
 * @mail yolo_215@163.com
 */
public class ChannelUtil {

    /**
     * 发送消息
     * 给本地channel发送消息
     *
     * @param channel    频道
     * @param wsBaseResp ws base resp
     */
    public static void sendMsg(Channel channel, WsBaseResp<?> wsBaseResp) {
        channel.writeAndFlush(new TextWebSocketFrame(JSONUtil.toJsonStr(wsBaseResp)));
    }
}
